
import { formatDate } from "../../utils/formatDate";
Component({
  options: {
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  },
  properties: {
    title: {
      type: String,
      value: "",
    },
    titleValue: {
      type: String,
      value: "",
    },
  },
  data: {
    date:formatDate(new Date()), // 日期选择器的选中值，初始为当前日期
  },
  computed: {
    dateFormat() {
      return this.data.date.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1年$2月$3日");
    },
  },
  methods: {
    // 日期改变触发事件
    bindDateChange(e) {
      const selectedDate = e.detail.value;
      const startTimestamp = Date.parse(selectedDate + " 00:00:00");
      const endTimestamp = startTimestamp + 24 * 60 * 60 * 1000 - 1; // 当天的最后一毫秒
      const formattedDate = formatDate(new Date(selectedDate)); // 格式化选中的日期
      this.setData({
        date: selectedDate,
      });
      this.triggerEvent("changeDate", {
        date: formattedDate,
        startTimestamp,
        endTimestamp,
      });
    },
  },
});
